package bean;

import org.junit.Test;

import java.util.*;

public class HashSetTest {

    @Test
    public void testHashSet() {
        String s = new String();
        HashMap hashMap = new HashMap();
        Hashtable hashtable = new Hashtable();
        hashMap.put("","");
        hashMap.get("");
        HashSet set = new HashSet();
        List<Node> list = new ArrayList<>();
        Node node1 = new Node(2);
        System.out.println("add1:" + set.add(node1));//add方法返回add是否成功
        Node node2 = new Node(5);
        System.out.println("add1:" + set.add(node2));
        Node node3 = new Node(7);
        System.out.println("add1:" + set.add(node3));
        Node node4 = new Node(2);
        System.out.println("add1:" + set.add(node4));
        getClass().getClassLoader();
    }

    class Node {

        public Node(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        Node next;
        int value;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Node)) return false;
            Node node = (Node) o;
            return getValue() == node.getValue();
        }

        @Override
        public int hashCode() {
            return Objects.hash(getValue());
        }
    }

}
